<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: Upgrade_1_0_1.php 289 2008-11-14 05:34:40Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Upgrade.PortalUpgrade');
class Upgrade_1_0_1 extends PortalUpgrade
{

	public function run()
	{
		parent::run();

		$db = $this->DbConnection;

		// Check that the admin portlet is installed
		$prow = $db->createCommand("select * from tblportlets where name='AdminPortlet'")->queryRow();
		if($prow === null)
		{
			try
			{
				$db->createCommand("insert into tblportlets(name,displayname,active) values('AdminPortlet','Admin menu','1')")->execute();
			}
			catch(Exception $e) {}
		}
		// Check that the Poll portlet is installed
		$prow = $db->createCommand("select * from tblportlets where name='PollPortlet'")->queryRow();
		if($prow === null)
		{
			try
			{
				$db->createCommand("insert into tblportlets(name,displayname,active) values('PollPortlet','Poll','1')")->execute();
			}
			catch(Exception $e) {}
		}

		// Check that the news portlet is installed
		$prow = $db->createCommand("select * from tblportlets where name='NewsPortlet'")->queryRow();
		if($prow === null)
		{
			try
			{
				$db->createCommand("insert into tblportlets(name,displayname,active) values('NewsPortlet','News','1')")->execute();
			}
			catch(Exception $e) {}
		}

		// Check that the news portlet is installed
		$prow = $db->createCommand("select * from tblportlets where name='SearchPortlet'")->queryRow();
		if($prow === null)
		{
			try
			{
				$db->createCommand("insert into tblportlets(name,displayname,active) values('SearchPortlet','Search','1')")->execute();
			}
			catch(Exception $e) {}
		}

		// update data for image potlet
		$ipdata = $db->createCommand("select * from tblconfig where name like 'ip_%'")->query();
		if($ipdata !== null && count($ipdata) > 0)
		{
			foreach($ipdata as $idata)
			{
				$newname			= "ImagePortlet_" . substr($idata['name'],3,999);
				$values				= unserialize($idata['value']);
				$imagename			= @$values[0];
				$imagewidth			= @$values[1];
				$imageheight		= @$values[2];
				$imageborder		= @$values[3];
				$imagebordercolor	= @$values[4];

				$value 		= serialize(array("imagename" => $imagename, "imagewidth" => $imagewidth, "imageheight" => $imageheight, "imageborder" => $imageborder, "imagebordercolor" => $imagebordercolor));
				$db->createCommand("update tblconfig set name='$newname',value='$value' where id=" . $idata['id'])->execute();
			}
		}

		// update data for SimpleText portlet
		$spdata = $db->createCommand("select * from tblconfig where name like 'st_%'")->query();
		if($spdata !== null && count($spdata) > 0)
		{
			foreach($spdata as $sdata)
			{
				$newname	= "SimpleTextPortlet_" . substr($sdata['name'],3,999);
				$db->createCommand("update tblconfig set name='$newname' where id=" . $sdata['id'])->execute();
			}
		}

		$this->UpdVersionNum('1.0.2');
	}
}
?>